/**
 * @author LKQ
 * @date 2021/12/26 12:20
 * @description 双重for循环很直接移动，但是无法AC，会超出时间限制
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(solution.maxArea(height));
    }

    public int maxArea(int[] height) {
        int n = height.length;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                ans = Math.max(Math.min(height[i], height[j]) * (j - i), ans);
            }
        }
        return ans;
    }
}
